# 数据准备
labels = ['Normal', 'Poisoning Attack']
krum_scores = [0.72, 0.41]
dtfl_scores = [0.89, 0.72]
x = np.arange(len(labels))

# 创建图表
plt.figure(figsize=(5, 3))
width = 0.3

bars1 = plt.bar(x - width/2, krum_scores, width, label='Krum', color='#ff00ff',hatch='/')
bars2 = plt.bar(x + width/2, dtfl_scores, width, label='DTFL', color='#1f77b4',hatch='\\')

# 添加数据标签
for bars in [bars1, bars2]:
    for bar in bars:
        height = bar.get_height()
        plt.text(bar.get_x() + bar.get_width()/2, height+0.02, 
                 f'{height:.2f}', ha='center', va='bottom')

# 设置标题和标签
# plt.title('Figure 4.6: F1 Score Under Different Conditions', fontsize=14)
plt.ylabel('F1 Score', fontsize=12)
plt.xticks(x, labels,fontsize=12)

plt.legend()
plt.ylim(0, 1.0)
# plt.grid(axis='y', linestyle='--', alpha=0.7)

# 添加性能对比标注
# plt.annotate('DTFL maintains 72% F1\nunder attack', 
#              xy=(1.1, 0.75), xytext=(1.3, 0.6),
#              arrowprops=dict(facecolor='black', shrink=0.05))

plt.tight_layout()
plt.savefig('Fig6.png', dpi=600)
plt.show()
